Ceph 使用 Paxos 演算法決定多個 mons 中,那個作為主要 mon。因此,本次部署將部署 3 個 mon,可允許 1 個 mon 失敗,以此避免單點失敗問題。
部署步驟如下:
以部署至 master1, worker1, worker2 主機為例:
#!/bin/bash
DOCKERIMAGE=ceph/daemon:v3.2.1-stable-3.2-luminous-debian-9-x86_64
NETWORK=10.13.13.0/24
MON1=master1
MON1IP=10.13.13.101
MON2=worker1
MON2IP=10.13.13.102
MON3=worker2
MON3IP=10.13.13.103
MONS=${MON1},${MON2},${MON3}
MONSIP=${MON1IP},${MON2IP},${MON3IP}
# Bootstrap Ceph by MON1
ssh ${MON1} "
docker run -d --net=host \
--restart=always \
-v /etc/ceph:/etc/ceph \
-v /var/log/ceph/:/var/log/ceph/ \
-v /var/lib/ceph/mon:/var/lib/ceph/mon \
-v /var/lib/ceph/bootstrap-mds:/var/lib/ceph/bootstrap-mds \
-v /var/lib/ceph/bootstrap-osd:/var/lib/ceph/bootstrap-osd \
-v /var/lib/ceph/bootstrap-rbd:/var/lib/ceph/bootstrap-rbd \
-v /var/lib/ceph/bootstrap-rgw:/var/lib/ceph/bootstrap-rgw \
-e MON_IP=${MON1IP} \
-e CEPH_PUBLIC_NETWORK=$NETWORK \
--name mon \
${DOCKERIMAGE} mon
"
for ROLE in osd mds rbd rgw
do
while ssh ${MON1} "sudo [ ! -f /var/lib/ceph/bootstrap-${ROLE}/ceph.keyring ]"
do
echo Waiting bootstrap-${ROLE}/ceph.keyring...
sleep 1
done
done
ssh ${MON1} "
sudo sed -i -e 's/^mon initial members = .*/mon initial members = ${MONS}/' /etc/ceph/ceph.conf ;
sudo sed -i -e 's/^mon host = .*/mon host = ${MONSIP}/' /etc/ceph/ceph.conf ;
"
ssh ${MON1} "
docker stop mon ; docker rm mon ;
sudo rm -rf /var/lib/ceph/mon ;
sudo mkdir -p ~/pack/ceph/etc ~/pack/ceph/var/lib/ceph ;
sudo cp -rf /etc/ceph ~/pack/ceph/etc/ ;
sudo cp -rf /var/lib/ceph/bootstrap-mds ~/pack/ceph/var/lib/ceph ;
sudo cp -rf /var/lib/ceph/bootstrap-osd ~/pack/ceph/var/lib/ceph ;
sudo cp -rf /var/lib/ceph/bootstrap-rbd ~/pack/ceph/var/lib/ceph ;
sudo cp -rf /var/lib/ceph/bootstrap-rgw ~/pack/ceph/var/lib/ceph ;
sudo chown -R 64045:64045 ~/pack/ceph/var/lib/ceph ;
"
for MON in ${MON2} ${MON3}
do
ssh ${MON} "sudo mkdir -p ~/pack/ceph"
ssh ${MON1} "sudo tar -zcpf - -C ~/pack/ceph ." | ssh ${MON} "sudo tar zxpf - -C ~/pack/ceph"
ssh ${MON} "
sudo cp -rf ~/pack/ceph/etc/ceph /etc ;
sudo cp -rf ~/pack/ceph/var/lib/ceph /var/lib ;
sudo mkdir -p /var/log/ceph ;
sudo chmod go-rwx /var/log/ceph /var/lib/ceph ;
sudo chown 64045:64045 /var/log/ceph /var/lib/ceph ;
sudo rm -rf ~/pack ;
"
done
ssh ${MON1} "sudo rm -rf ~/pack"
for t in ${MON1},${MON1IP} ${MON2},${MON2IP} ${MON3},${MON3IP}
do
IFS=","
set -- $t
MON=$1
MONIP=$2
ssh ${MON} "
docker run -d --net=host \
--restart=always \
-v /etc/ceph:/etc/ceph \
-v /var/log/ceph/:/var/log/ceph/ \
-v /var/lib/ceph/mon:/var/lib/ceph/mon \
-v /var/lib/ceph/bootstrap-mds:/var/lib/ceph/bootstrap-mds \
-v /var/lib/ceph/bootstrap-osd:/var/lib/ceph/bootstrap-osd \
-v /var/lib/ceph/bootstrap-rbd:/var/lib/ceph/bootstrap-rbd \
-v /var/lib/ceph/bootstrap-rgw:/var/lib/ceph/bootstrap-rgw \
-e MON_IP=${MONIP} \
-e CEPH_PUBLIC_NETWORK=$NETWORK \
--name mon \
${DOCKERIMAGE} mon
"
done
ceph.conf 例:
[global]
fsid = 03893329-f6f6-45c7-a1fb-eeeaf8a5c445
mon initial members = master1,worker1,worker2
mon host = 10.13.13.101,10.13.13.102,10.13.13.103
public network = 10.13.13.0/24
cluster network = 10.13.13.0/24
osd journal size = 100
log file = /dev/null
部署結果,共 3 個 mon daemons:
$ ssh master1 docker exec mon ceph -s
cluster:
id: 03893329-f6f6-45c7-a1fb-eeeaf8a5c445
health: HEALTH_OK
services:
mon: 3 daemons, quorum master1,worker2,worker1
mgr: no daemons active
osd: 0 osds: 0 up, 0 in
data:
pools: 0 pools, 0 pgs
objects: 0 objects, 0B
usage: 0B used, 0B / 0B avail
pgs: